# coding=utf8
#


import json
from django.conf import settings

from django.http import HttpResponse


def make_api_response(result=None, page_info=None, message="", status_code=200):
    """
        构造api结构的返回
        结构大致如下:
        {success: True/False,
         message: error message,
         data: result,
         result_info: result_info,
         }
    """
    ret = {"success": len(message) == 0,
           "message": message,
           "data": result,
           "code": status_code}

    if page_info:
        ret.update({"page_info": page_info})

    return HttpResponse(json.dumps(ret),
                        content_type="application/json",
                        status=int(status_code))
